//
//  AddAddressViewController.m
//  DianDangDai
//
//  Created by bhf on 2017/12/25.
//  Copyright © 2017年 bhf. All rights reserved.
//

#import "AddAddressViewController.h"

@interface AddAddressViewController ()

@property (strong, nonatomic) IBOutlet UIButton *defaultBtn;
@property (nonatomic, assign) BOOL isDefalut;
@end

@implementation AddAddressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _isDefalut = _model.is_default;

}

- (void)setupViews {
    
    self.name.text = self.model.username;
    self.phone.text = self.model.mobile;
    self.youbian.text = [NSString stringWithFormat:@"%ld",self.model.postcode];
    self.sheng.text = self.model.province;
    self.shi.text = self.model.city;
    self.qu.text = self.model.area;
    if (self.model.is_default) {
         [self.defaultBtn setImage:[UIImage imageNamed:@"radio1-1"] forState:UIControlStateNormal];
    } else {
         [self.defaultBtn setImage:[UIImage imageNamed:@"radio2-1"] forState:UIControlStateNormal];
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)deafult:(UIButton *)sender {
    if (_isDefalut) {
        [self.defaultBtn setImage:[UIImage imageNamed:@"radio2-1"] forState:UIControlStateNormal];
        _isDefalut = NO;
    }
    if (!_isDefalut) {
        [self.defaultBtn setImage:[UIImage imageNamed:@"radio1-1"] forState:UIControlStateNormal];
        _isDefalut = YES;
    }
    
}
- (IBAction)baocun:(UIButton *)sender {
    NSString *urlString = [NSString stringWithFormat:@"%@OPT=1033&id=%ld&is_default=%d&postcode=%@&username=%@&mobile=%@&area=%@&city=%@&province=%@&sign=%@",API_LOGIN_URL_STRING,(long)_model.id,_isDefalut,_youbian.text,_name.text,_phone.text,_qu.text,_shi.text,_sheng.text,USER_SIGN];
    NSLog(@"%@",urlString);
    [[CDHttpHelper defaultCDHttpHelper] get:urlString params:nil success:^(id responseObj) {
        NSLog(@"%@",[responseObj mj_JSONString]);
        //        NSDictionary *dict = [responseObj objectFromJSONData];
        //        NSLog(@"%@",dict);
        
    } failure:^(NSError *error) {
        
    } showHUD:YES];
}



@end
